//
//  BaseViewController.swift
//  SwiftWB
//
//  Created by 钟清 on 17/3/25.
//  Copyright © 2017年 Zhong Qing. All rights reserved.
//

import UIKit

class BaseViewController: UITableViewController {

    /// 标记，记录是否已经登陆
    let isLogin = UserAccount.isLogin()
    
    var visitorView : VisitorView?
    override func loadView() {
        isLogin ? super.loadView() : setUpVisitorView()
    }
    
    // MARK - : 内部控制visitor View
    private func setUpVisitorView() {
        visitorView = VisitorView.visitorView()
        view = visitorView
        /// 点击登陆按钮
        visitorView?.loginButton.addTarget(self, action: #selector(BaseViewController.loginButtonClick(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        /// 点击注册按钮
        visitorView?.registerButton.addTarget(self, action: #selector(BaseViewController.registerButtonClick(_:)), forControlEvents: UIControlEvents.TouchUpInside)
        /// 导航条登陆按钮
//        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseViewController.loginButtonClick(_:)))
//        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(BaseViewController.registerButtonClick(_:)))
//        
        /* 导航条注册按钮 */
        // visitorView?.delegate = self
        
    }
    @objc private func loginButtonClick(btn : UIButton) {
        guard let oauthVC = R.storyboard.oAuth.initialViewController() else {
            return
        }
        presentViewController(oauthVC, animated: true, completion: nil)
    }
    @objc private func registerButtonClick(btn : UIButton) {
        ZQLog("")
    }

}

//extension BaseViewController : VisitorViewDelegate {
//    func visitorViewDidClickLoginButton(visitor: VisitorView) {
//        ZQLog("")
//    }
//    func visitorViewDidClickRegisterButton(visitor: VisitorView) {
//        ZQLog("")
//    }
//}
